<?php
/**
 * Created by PhpStorm.
 * User: wangye
 * Date: 19-2-14
 * Time: 下午4:49
 */

//自动爬取html代码并返回
function setCurl ($url,$proxy_flag = false,$proxy=array()){
    $ch = curl_init($url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);//返回字符串
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,0);//不限时链接等待
    curl_setopt($ch,CURLOPT_HEADER,FALSE);//不输出head内容
    curl_setopt($ch,CURLOPT_TIMEOUT,120);//curl脚步限时

    if ('https' == substr($url,0,5)){
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);//绕开https验证
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);//绕开https验证域名
    }

    if ($proxy_flag){
        curl_setopt($ch,CURLOPT_PROXY,$proxy['name'].':'.$proxy['pass'].'@'.$proxy['host']);
        curl_setopt($ch,CURLOPT_PROXYPORT,$proxy['port']);
    }
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

function trimAll($str){
    $pattern = array(' ','&nbsp','  ','\t','\n','\r');
    $str = str_replace($pattern,'',$str);
}

$url = "https://baike.baidu.com/item/%E6%83%85%E4%BA%BA%E8%8A%82/30001#hotspotmining";
$html =setCurl($url);
//$html = trimAll($html);
var_dump($html);